// Author: wsfuyibing <682805@qq.com>
// Date: 2025-06-11

package responses

import (
	"gitee.com/go-libs/db-xorm/db"
	"server/app/http/models"
	"server/app/kind"
)

// OrderLogResponse
// 订单日志.
type OrderLogResponse struct {
	Id            int64
	OrderId       int64
	Operation     kind.OrderOperation
	OperationText string
	Link          kind.Link
	LinkParams    kind.LinkParams
	Message       string
	CreatedAt     db.Datetime

	User *UserResponse `json:",omitempty"`
}

// With
// 数据绑定.
func (o *OrderLogResponse) With(m *models.OrderLog) *OrderLogResponse {
	o.Id = m.Id
	o.OrderId = m.OrderId
	o.Operation = m.Operation
	o.OperationText = m.Operation.Text()
	o.Link = m.Link
	o.LinkParams = m.LinkParams
	o.Message = m.Message
	o.CreatedAt = m.CreatedAt
	return o
}

// WithUser
// 绑定用户.
func (o *OrderLogResponse) WithUser(m *models.Users) *OrderLogResponse {
	if m != nil {
		o.User = (&UserResponse{}).With(m)
	}
	return o
}
